<include file="Public/min-header" />
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
	<include file="Public/breadcrumb" />
	<section class="content ">
		<!-- Main content -->
		<div class="container-fluid">
			<div class="pull-right">
				<a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i
					 class="fa fa-reply"></i></a>
			</div>
			<div class="panel panel-default">
				<div class="panel-heading">
					<h3 class="panel-title"><i class="fa fa-list"></i> 添加活动</h3>
				</div>
				<div class="panel-body ">
					<!--表单数据-->
					<form action="" method="post">
						<!--通用信息-->
						<div class="tab-content col-md-10">
							<div class="tab-pane active" id="tab_tongyong">
								<table class="table table-bordered">
									<tbody>
										<tr>
											<td class="col-sm-2">活动名称：</td>
											<td class="col-sm-4">
												<input type="text" value="{$free_prizes.title}" class="form-control" id="title" name="title">
												<span id="err_attr_title" style="color:#F00; display:none;"></span>
											</td>
											<td class="col-sm-4">请填写活动名称
											</td>
										</tr>
										<tr>
											<td>选择商品:</td>
											<td>
												<div class="form-group">
													<div class="col-xs-2">
														<a class="btn btn-primary" href="javascript:void(0);" onclick="selectGoods()"><i class="fa fa-search"></i>添加商品</a>
													</div>
													<div class="col-xs-2">
														<span id="err_goods" style="color:#F00; display:none;">请添加下单商品</span>
													</div>
												</div>
											</td>
										</tr>
										<tr>
											<td colspan="2">
												<div class="form-group">
													<table class="table table-bordered">
														<thead>
															<tr>
																<th style="display:none">选择</th>
																<th class="text-left">商品名称</th>
																<th class="text-left">价格</th>
																<th class="text-left">库存</th>
																<th class="text-left">操作</th>
															</tr>
														</thead>
														<tbody id="goods_list">
															<foreach name="freeprizess_goods" item="vo">
																<tr>
																	<td style="display:none"><input type="checkbox" name="goods_id[]" checked="checked" value="{$vo.goods_id}" /></td>
																	<td class="text-left">{$vo.goods_name}</td>
																	<td class="text-left">{$vo.shop_price}</td>
																	<td class="text-left">{$vo.store_count}</td>
																	<td class="text-left"><a href="javascript:void(0)" onclick="javascript:$(this).parent().parent().remove();">删除</a></td>
																</tr>
															</foreach>
														</tbody>
													</table>
												</div>
											</td>
										</tr>
										<tr class="timed">
											<td>活动起始日期:</td>
											<td>
												<div class="input-prepend input-group">
													<span class="add-on input-group-addon">
														<i class="glyphicon glyphicon-calendar fa fa-calendar"> </i>
													</span>
													<input type="text" value="{$free_prizes.start_time|date='Y-m-d H:i:s',###}" class="form-control" id="start_time"
													 name="start_time">
												</div>
											</td>
											<td class="col-sm-4"></td>
										</tr>

										<tr class="timed">
											<td>活动结束日期:</td>
											<td>
												<div class="input-prepend input-group">
													<span class="add-on input-group-addon">
														<i class="glyphicon glyphicon-calendar fa fa-calendar"> </i>
													</span>
													<input type="text" value="{$free_prizes.end_time|date='Y-m-d H:i:s',###}" class="form-control" id="end_time"
													 name="end_time">
												</div>
											</td>
											<td class="col-sm-4"></td>
										</tr>
										<tr>
											<td>所需积分：</td>
											<td>
												<input type="text" value="{$free_prizes.integral}" class="form-control active" id="integral" name="integral"
												 onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" />
											</td>
											<td class="col-sm-4">订单消费比例所需积分</td>
										</tr>
										<tr>
											<td>兑换比例：</td>
											<td>
												<input type="text" value="{$free_prizes.ratio}" class="form-control active" id="ratio" name="ratio" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"
												 onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" />
											</td>
											<td class="col-sm-4">消费金额兑换积分比例 比如0.5 消费2元可得1积分</td>
										</tr>


										<tr>
											<td>活动状态:</td>
											<td id="sale-status">
												<input name="is_on_sale" type="radio" value="0" <if condition="$free_prizes['is_on_sale'] eq 0">checked</if>>下架
												<input name="is_on_sale" type="radio" value="1" <if condition="$free_prizes['is_on_sale'] eq 1">checked</if> >上架
											</td>
										</tr>
										<tr>
										    <td>活动须知：</td> 
										    <td>
										    <textarea rows="5" cols="30" name="content_string">{$free_prizes.content_string}</textarea>
											一行为一条须知
										    <span id="err_content_string" style="color:#F00; display:none;"></span>
										    </td>
										</tr>     
									</tbody>
									<tfoot>
										<tr>
											<td>
												
												<input type="hidden" name="id" value="{$free_prizes.id}">
												<input type="hidden" name="content" value="{$free_prizes.content}">
											</td>
											<td class="col-sm-4"></td>
											<td class="text-right"><input class="btn btn-primary" type="submit" value="保存"></td>
										</tr>
									</tfoot>
								</table>
							</div>
						</div>
					</form>
					<!--表单数据-->
				</div>
			</div>
		</div>
	</section>
</div>

<script>
	$('input[type="radio"]').click(function() {
		if ($(this).val() == 0) {
			$('.timed').hide();
		} else {
			$('.timed').show();
		}
	})

	function selectGoods() {
		var goods_id = [];
		//过滤选择重复商品
		$('input[name*="goods_id"]').each(function(i, o) {
			goods_id.push($(o).val());
		});
		var url = '/index.php?m=Admin&c=Freeprizes&a=search_goods&goods_id=' + goods_id + '&t=' + Math.random();
		layer.open({
			type: 2,
			title: '选择商品',
			shadeClose: true,
			shade: 0.3,
			area: ['70%', '80%'],
			content: url,
		});
	}

	function call_back(table_html) {
		layer.closeAll('iframe');
		$('#goods_list').append(table_html);
	}

	$(function() {
		data_pick('start_time');
		data_pick('end_time');
		$('input[type="radio"]:checked').trigger('click');
	})

	function data_pick(id) {
		var myDate = new Date();
		$('#' + id).daterangepicker({
			format: "YYYY-MM-DD HH:mm:ss",
			singleDatePicker: true,
			showDropdowns: true,
			minDate: myDate.getFullYear() + '-' + myDate.getMonth() + '-' + myDate.getDate(),
			maxDate: '2030-01-01',
			timePicker: true, //是否显示小时和分钟  
			timePickerIncrement: 1, //time选择递增数
			timePicker12Hour: false, //是否使用12小时制来显示时间 		
			locale: {
				applyLabel: '确定',
				cancelLabel: '取消',
				fromLabel: '起始时间',
				toLabel: '结束时间',
				customRangeLabel: '自定义',
				daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
				monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
				firstDay: 1
			}
		});
	}
</script>
</body>
</html>
